#include <iostream>

template <class T>
struct node{
    T data;
    node* left;
    node* right;
};
template <class T>
node<T> *search(node<T>*head,node<T> *p,T key){
    Node<T> *now=p;
    while(now!=head->right&&now->data!=key){
        now=now->left;   
    }
    if (now->data==key){
        p=now;
        return now;
    }
    now=p->right;
    while (now!=NULL && now->data!=key){
        now=now->right;
    }
    if (now->data==key){
        p=now;
        return now;
    }
    return NULL;
}



